package routes

import  (
	"github.com/gin-gonic/gin"
	"wangblog/api/v1"
	"wangblog/middleware"
	"wangblog/utils"
)

func InitRouter(){
	gin.SetMode(utils.AppMode)
	r:=gin.New()
	r.Use(middleware.Loggoer())
	r.Use(gin.Recovery())
	r.Use(middleware.Cors())
	auth:=r.Group("api/v1")
		auth.Use(middleware.JwtToken())
	{
		//用户模块的路由接口
		auth.PUT("user/:id",v1.EditUser)
		auth.DELETE("user/:id",v1.DeleteUser)
		//auth的路由接口
		auth.POST("category/add",v1.AddCategory)
		auth.PUT("category/:id",v1.EditCate)
		auth.DELETE("category/:id",v1.DeleteCate)
		//auth的路由接口
		auth.POST("article/add",v1.AddArticle)
		auth.PUT("article/:id",v1.EditArt)
		auth.DELETE("article/:id",v1.DeleteArt)
		//上传文件
		auth.POST("upload",v1.UpLoad)
	}
	router:=r.Group("api/v1")
	{
		router.POST("user/add",v1.AddUser)
		router.GET("users",v1.GetUsers)
		router.GET("category",v1.GetCate)
		router.GET("article",v1.GetArt)
		router.GET("article/list/:id",v1.GetCateArt)
		router.GET("article/info/:id",v1.GetArtInfo)
		router.POST("login",v1.Login)
	}

	r.Run(utils.HttpPort)
}
